/*
 * 文件名：FtpImageUpThread.java	 
 * 时     间：上午11:19:22
 * 作     者：lyf      
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.manager.thread;

import java.util.List;

import com.cz073586.message.websocket356.push.PushManager;
import com.cz073586.message.websocket356.transfer.TransferVo;
import com.cz073586.tools.util.Log4jUtil;
import com.local.entity.vo.CarBillVo;
import com.local.entity.vo.PushCarInOrOutInfoVo;
import com.local.model.Crossing;
import com.local.model.LocalStation;
import com.local.service.face.CarInAndOutService;
import com.local.service.face.CrossingService;

/**
 * 类描述:异步更新进出场纪录图片处理线程
 * 
 * @ClassName: FtpImageUpThread
 * @author lyf
 * @date 2016年4月3日 上午11:19:22
 */
public class FtpImageUpThread implements Runnable
{
	private Log4jUtil log = Log4jUtil.getLog4j(FtpImageUpThread.class);
	private CarBillVo carBillVo;
	
	private CarInAndOutService carInAndOutService;
	
	private CrossingService crossionService;
	
	public FtpImageUpThread(CarBillVo carBillVo,
			CarInAndOutService carInAndOutService,
			CrossingService crossionService)
	{
		super();
		this.carBillVo = carBillVo;
		this.carInAndOutService = carInAndOutService;
		this.crossionService = crossionService;
	}
	
	@Override
	public void run()
	{
		try
		{
			carInAndOutService.asyncPhotoForInOrOut(carBillVo);
			
			// 推送到前端页面
			if (carBillVo.isPushImage())
			{
				PushCarInOrOutInfoVo pushInfo = new PushCarInOrOutInfoVo();
				
				pushInfo.setPic1(carBillVo.getPic1());
				pushInfo.setPic2(carBillVo.getPic2());
				pushInfo.setRecordId(carBillVo.getRecordId());
				// 通过设备编码查询路口数 这些查询需要放入线程里。TODO 张威
				List<Crossing> crossList = crossionService
						.queryCrossingByEquimentNo(carBillVo.getEquipment());
				
				if (crossList.isEmpty())
				{
					return;
				}
				
				// 通过路口数查询需要推送多少个岗亭
				List<LocalStation> stationList = crossionService
						.queryStaionsByCrosList(crossList);
				pushInfo.setCrossList(crossList);
				pushInfo.setStationList(stationList);
				
				TransferVo<PushCarInOrOutInfoVo> trans = new TransferVo<PushCarInOrOutInfoVo>();
				trans.setEventType("ftpPhoto");
				
				trans.setData(pushInfo);
				PushManager.instance().pushMessage(trans);
			}// 推送
		} catch (Exception e)
		{
			log.error("FtpImageUpThread->", e);
		}
	}
	
}
